package com.awspaas.user.apps.processforsap.web;

import com.actionsoft.bpms.commons.database.RowMap;
import com.actionsoft.bpms.commons.mvc.view.ResponseObject;
import com.actionsoft.bpms.server.UserContext;
import com.actionsoft.bpms.server.bind.annotation.Controller;
import com.actionsoft.bpms.server.bind.annotation.Mapping;
import com.actionsoft.bpms.util.DBSql;
import com.actionsoft.sdk.local.SDK;

import java.util.List;
import java.util.stream.Collectors;

@Controller
public class SapUnitController {
    @Mapping("wl.getunit")
    public static ResponseObject getUnit (UserContext userContext,String matlGroup,String matlType){
        ResponseObject responseObject = ResponseObject.newOkResponse("查询成功！");
        String sql = "select * from BO_ACT_DICT_KV_ITEM where  DICTKEY='WL_UNIT'";
        List<RowMap> list = DBSql.getMaps(sql);
        //先判断有没有特殊的
        List<RowMap> resultList = list.stream().filter(rowMap -> rowMap.getString("CNNAME").equals(matlGroup)&&rowMap.getString("EXTTEXT2").equals(matlType)).collect(Collectors.toList());
        if (resultList!=null && resultList.size()>0){
            responseObject.setData(resultList.get(0).getString("EXTTEXT1"));
        }else{
           resultList = list.stream().filter(rowMap -> rowMap.getString("CNNAME").equals(matlGroup)&&rowMap.getString("EXTTEXT2").equals("NORMAL")).collect(Collectors.toList());
            if (resultList!=null && resultList.size()>0){
                responseObject.setData(resultList.get(0).getString("EXTTEXT1"));
            }
        }
        return responseObject;
    }
}
